// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
// import com.alibaba.druid.sql.ast.statement.SQLLockTableStatement;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleLockTableStatement.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLName.h"
#include "../../../../ast/SQLObject.h"
#include "../../../../ast/statement/SQLExprTableSource.h"
#include "../../visitor/OracleASTVisitor.h"

OracleLockTableStatement_LockMode_ptr OracleLockTableStatement_LockMode::ROW_SHARE = OracleLockTableStatement_LockMode_ptr(new OracleLockTableStatement_LockMode(1ULL << 0, make_string_ptr("ROW SHARE")));
OracleLockTableStatement_LockMode_ptr OracleLockTableStatement_LockMode::ROW_EXCLUSIVE = OracleLockTableStatement_LockMode_ptr(new OracleLockTableStatement_LockMode(1ULL << 1, make_string_ptr("ROW EXCLUSIVE")));
OracleLockTableStatement_LockMode_ptr OracleLockTableStatement_LockMode::SHARE_UPDATE = OracleLockTableStatement_LockMode_ptr(new OracleLockTableStatement_LockMode(1ULL << 2, make_string_ptr("SHARE UPDATE")));
OracleLockTableStatement_LockMode_ptr OracleLockTableStatement_LockMode::SHARE = OracleLockTableStatement_LockMode_ptr(new OracleLockTableStatement_LockMode(1ULL << 3, make_string_ptr("SHARE")));
OracleLockTableStatement_LockMode_ptr OracleLockTableStatement_LockMode::SHARE_ROW_EXCLUSIVE = OracleLockTableStatement_LockMode_ptr(new OracleLockTableStatement_LockMode(1ULL << 4, make_string_ptr("SHARE ROW EXCLUSIVE")));
OracleLockTableStatement_LockMode_ptr OracleLockTableStatement_LockMode::EXCLUSIVE = OracleLockTableStatement_LockMode_ptr(new OracleLockTableStatement_LockMode(1ULL << 5, make_string_ptr("EXCLUSIVE")));

OracleLockTableStatement_LockMode::OracleLockTableStatement_LockMode(uint64_t mask, string_ptr name)
{
  this->mask = mask;
  this->name = name;
}
string_ptr OracleLockTableStatement_LockMode::toString()
{
  return this->name;
}

BOOL_ptr OracleLockTableStatement::isNoWait()
{
  return noWait;
}

void OracleLockTableStatement::setNoWait(BOOL_ptr noWait)
{
  this->noWait = noWait;
}

SQLExpr_ptr OracleLockTableStatement::getWait()
{
  return wait;
}

void OracleLockTableStatement::setWait(SQLExpr_ptr wait)
{
  this->wait = wait;
}

SQLExprTableSource_ptr OracleLockTableStatement::getTable()
{
  return table;
}

void OracleLockTableStatement::setTable(SQLExprTableSource_ptr table)
{
  if (table != nullptr)
  {
    table->setParent(SharedObject(OracleLockTableStatement));
  }
  this->table = table;
}

void OracleLockTableStatement::setTable(SQLName_ptr table)
{
  this->setTable(SQLExprTableSource_ptr(new SQLExprTableSource(table)));
  this->table->setParent(SharedObject(OracleLockTableStatement));
}

OracleLockTableStatement_LockMode_ptr OracleLockTableStatement::getLockMode()
{
  return lockMode;
}

void OracleLockTableStatement::setLockMode(OracleLockTableStatement_LockMode_ptr lockMode)
{
  this->lockMode = lockMode;
}

SQLExpr_ptr OracleLockTableStatement::getPartition()
{
  return partition;
}

void OracleLockTableStatement::setPartition(SQLExpr_ptr partition)
{
  this->partition = partition;
}

// @Override
void OracleLockTableStatement::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleLockTableStatement)))
  {
    acceptChild(visitor, table);
    acceptChild(visitor, partition);
    acceptChild(visitor, wait);
  }
  visitor->endVisit(SharedObject(OracleLockTableStatement));
}

SQLObject_list_ptr OracleLockTableStatement::getChildren()
{
  SQLObject_list_ptr children = std::make_shared<std::list<SQLObject_ptr>>();
  if (table != nullptr)
  {
    children->push_back(table);
  }
  if (wait != nullptr)
  {
    children->push_back(wait);
  }
  if (partition != nullptr)
  {
    children->push_back(partition);
  }
  return children;
}
